package org.jeecg.modules.demo.znnqjc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.demo.znnqjc.entity.ZwglZwgc;
import org.jeecg.modules.demo.znnqjc.entity.ZwglZwgcfb;
import org.jeecg.modules.demo.znnqjc.mapper.ZwglZwgcfbMapper;
import org.jeecg.modules.demo.znnqjc.mapper.ZwglZwgcMapper;
import org.jeecg.modules.demo.znnqjc.service.IZwglZwgcService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;
import java.util.Collection;

/**
 * @Description: 作物估产
 * @Author: jeecg-boot
 * @Date: 2023-04-20
 * @Version: V1.0
 */
@Service
public class ZwglZwgcServiceImpl extends ServiceImpl<ZwglZwgcMapper, ZwglZwgc> implements IZwglZwgcService {

    @Autowired
    private ZwglZwgcMapper zwglZwgcMapper;
    @Autowired
    private ZwglZwgcfbMapper zwglZwgcfbMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delMain(String id) {
        zwglZwgcfbMapper.deleteByMainId(id);
        zwglZwgcMapper.deleteById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delBatchMain(Collection<? extends Serializable> idList) {
        for (Serializable id : idList) {
            zwglZwgcfbMapper.deleteByMainId(id.toString());
            zwglZwgcMapper.deleteById(id);
        }
    }

    @Override
    public Result getzwgc(String nianfen) {
        QueryWrapper<ZwglZwgc> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("psrq", nianfen);
        List<ZwglZwgc> list = zwglZwgcMapper.selectList(queryWrapper);
        return Result.OK(list);
    }

    @Override
    public Result getzwgca(String lx,String psrq) {
        QueryWrapper<ZwglZwgc> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("lx", lx);
        queryWrapper.eq("psrq",psrq);
        List<ZwglZwgc> list = zwglZwgcMapper.selectList(queryWrapper);
        System.out.println(list);
        return Result.OK(list);
    }
    @Override
    public Result getzwgcb(String lx, String nianfen) {
        QueryWrapper<ZwglZwgc> queryWrapper = new QueryWrapper<>();
        if (lx.equals("玉米")){
            queryWrapper.eq("psrq", nianfen).and(qw->qw.eq("lx","玉米"));
            List<ZwglZwgc> list = zwglZwgcMapper.selectList(queryWrapper);
            return Result.OK(list);
        } else if (lx.equals("水稻")) {
            queryWrapper.eq("psrq", nianfen).and(qw->qw.eq("lx","水稻"));
            List<ZwglZwgc> list = zwglZwgcMapper.selectList(queryWrapper);
            return Result.OK(list);
        }else {
            queryWrapper.eq("psrq", nianfen).and(qw->qw.eq("lx","大豆"));
            List<ZwglZwgc> list = zwglZwgcMapper.selectList(queryWrapper);
            return Result.OK(list);
        }


    }

    @Override
    public Result getzwgcdkyumi(String dkbh) {
        QueryWrapper<ZwglZwgcfb> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dkbh", dkbh);
        queryWrapper.like("wj", "1648947614205767681");
        List<ZwglZwgcfb> list = zwglZwgcfbMapper.selectList(queryWrapper);
        return Result.OK(list);
    }

    @Override
    public Result getzwgcdkshuidao(String dkbh) {
        QueryWrapper<ZwglZwgcfb> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dkbh", dkbh);
        queryWrapper.like("wj", "1648948422091632642");
        List<ZwglZwgcfb> list = zwglZwgcfbMapper.selectList(queryWrapper);
        return Result.OK(list);
    }

    @Override
    public Result getzwgcdkdadou(String dkbh) {
        QueryWrapper<ZwglZwgcfb> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dkbh", dkbh);
        queryWrapper.like("wj", "1648949945991327746");
        List<ZwglZwgcfb> list = zwglZwgcfbMapper.selectList(queryWrapper);
        return Result.OK(list);
    }


    @Override
    public Result getzwgczdfxzuoa(String nianfen) {
        QueryWrapper<ZwglZwgc> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("psrq", nianfen);
        List<ZwglZwgc> list = zwglZwgcMapper.selectList(queryWrapper);
        return Result.OK(list);
    }

    @Override
    public Result getzwgczdfxzuo(String nianfen, String lx) {
        QueryWrapper<ZwglZwgc> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("psrq", nianfen);
        queryWrapper.eq("lx", lx);
        List<ZwglZwgc> list = zwglZwgcMapper.selectList(queryWrapper);
        return Result.OK(list);
    }

    @Override
    public Result getzwgczdfxyoua(String nianfen) {
        QueryWrapper<ZwglZwgc> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("psrq", nianfen);
        List<ZwglZwgc> list = zwglZwgcMapper.selectList(queryWrapper);
        return Result.OK(list);
    }

    @Override
    public Result getzwgczdfxyou(String nianfen, String lx) {
        QueryWrapper<ZwglZwgc> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("psrq", nianfen);
        queryWrapper.eq("lx", lx);
        List<ZwglZwgc> list = zwglZwgcMapper.selectList(queryWrapper);
        return Result.OK(list);
    }
    @Override
    public Result getzzgcdkcx(String dkmc,String id) {
        QueryWrapper<ZwglZwgcfb> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dkmc", dkmc);
        queryWrapper.like("wj", id);
        List<ZwglZwgcfb> list = zwglZwgcfbMapper.selectList(queryWrapper);
        return Result.OK(list);
    }
    @Override
    public Result getzzgcdkcxa(String dkmc) {
        QueryWrapper<ZwglZwgcfb> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dkmc", dkmc);
        queryWrapper.like("wj", "1648948422091632642");
        List<ZwglZwgcfb> list = zwglZwgcfbMapper.selectList(queryWrapper);
        return Result.OK(list);
    }
    @Override
    public Result getzzgcdkcxb(String dkmc) {
        QueryWrapper<ZwglZwgcfb> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dkmc", dkmc);
        queryWrapper.like("wj", "1648947614205767681");
        List<ZwglZwgcfb> list = zwglZwgcfbMapper.selectList(queryWrapper);
        return Result.OK(list);
    }
    @Override
    public Result getgclista(){
        QueryWrapper<ZwglZwgc> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("distinct psrq");
        List<ZwglZwgc> result = zwglZwgcMapper.selectList(queryWrapper);
        return Result.ok(result);
    }
    @Override
    public Result getgclistb(){
        QueryWrapper<ZwglZwgc> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("distinct lx");
        List<ZwglZwgc> result = zwglZwgcMapper.selectList(queryWrapper);
        return Result.ok(result);
    }
    @Override
    public Result getdbfxa(String lx){
        QueryWrapper<ZwglZwgc> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("distinct psrq");
        queryWrapper.eq("lx",lx);
        List<ZwglZwgc> result = zwglZwgcMapper.selectList(queryWrapper);
        return Result.ok(result);
    }

}
